﻿Imports DTO
Imports BUS
Public Class Form_Main

    Private Sub Form_Main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try

            Dim staffBus As New StaffBUS()
            Dim staffDto As StaffDTO = staffBus.GetStaffById(Utilities.ConfigReader.GetString("idLogin"))
            lblNameLogin.Text = "Hello " + staffDto.LName + " " + staffDto.FName
            Dim role As String = staffDto.Role
            If Not role.Equals("") AndAlso role.Equals("staff") Then
                TabControlMain.TabPages.Remove(tabReport)
            End If
            ''Tab 1
            LoadDataTab_1()
            'LoadDataTab_2("")
            'LoadTabService()
            'LoadTabCheckOut()
            ''Tab 2
            ' LoadDataTab_2()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#Region "Tab 1"

    Private Sub LoadDataTab_1(Optional optionShowAll As Boolean = False)
        SetClearReservation()
        Dim roomBus As New RoomBUS()
        Dim listRoom As List(Of RoomDTO) = roomBus.GetListRoom()
        If listRoom.Count > 0 Then
            Dim dt As New DataTable()
            ''Type-Capacity-Price
            dt.Columns.Add(New DataColumn("RoomId", GetType(String)))
            dt.Columns.Add(New DataColumn("Type", GetType(String)))
            dt.Columns.Add(New DataColumn("Capacity", GetType(String)))
            dt.Columns.Add(New DataColumn("Price", GetType(String)))
            Dim dr As DataRow
            Dim roomDto As RoomDTO
            Dim bookroomBus As New BookRoomBUS()
            Dim listbookroom As List(Of BookRoomDTO) = bookroomBus.GetListBookRoomByBookingId(GetBookingIdFromHidden)
          
            For i As Integer = 0 To listRoom.Count - 1
                roomDto = listRoom(i)
                If roomDto.Status.Equals("free") Then
                    dr = dt.NewRow()
                    dr("RoomId") = roomDto.RoomID
                    dr("Type") = roomDto.Type
                    dr("Capacity") = roomDto.Capacity
                    dr("Price") = roomDto.Price
                    dt.Rows.Add(dr)
                End If
                If optionShowAll = True Then
                    If listbookroom IsNot Nothing AndAlso listbookroom.Count > 0 Then
                        For j As Integer = 0 To listbookroom.Count - 1
                            If listbookroom(j).RoomID = roomDto.RoomID AndAlso Not roomDto.Status.Equals("free") Then
                                dr = dt.NewRow()
                                dr("RoomId") = roomDto.RoomID
                                dr("Type") = roomDto.Type
                                dr("Capacity") = roomDto.Capacity
                                dr("Price") = roomDto.Price
                                dt.Rows.Add(dr)
                            End If
                        Next
                    End If
                End If
            Next
            gridListRoom.DataSource = dt
        End If
        ' gridListRoom.DataSource = listRoom
    End Sub

    Private Sub btnSubmitBooking_Click(sender As Object, e As EventArgs) Handles btnSubmitBooking.Click
        Try
            If IsBooking() Then
                Dim customerBus As New CustomerBUS()
                Dim bookingBus As New BookingBUS()
                Dim bookromBus As New BookRoomBUS()
                Dim roomBus As New RoomBUS()
                Dim bookingIdModify As Integer = 0
                Dim custId As Integer = 1
                Dim staffId As Integer = Utilities.ConfigReader.GetString("idLogin")
                Dim dateIn As DateTime = dtpDateIn.Text
                Dim dateOut As DateTime = dtpDateOut.Text

                If lblHidden.Text > "" AndAlso IsNumeric(lblHidden.Text) Then
                    bookingIdModify = lblHidden.Text
                    Dim bookingModify As BookingDTO = bookingBus.GetByBookingId(bookingIdModify)
                    If bookingModify.Status.Equals("pending") Then
                        customerBus.Update(bookingModify.CustomerID, txtFName.Text, txtLName.Text, txtPhone.Text, txtPassport.Text)
                        bookingBus.Update(bookingIdModify, dateIn, dateOut)
                        bookromBus.Delete(bookingIdModify)
                        Dim listBookRoom As List(Of BookRoomDTO) = bookromBus.GetListBookRoomByBookingId(bookingIdModify)
                        For j As Integer = 0 To listBookRoom.Count - 1
                            roomBus.Update(listBookRoom(j).RoomID, "free")
                        Next
                        '' 
                        For i As Integer = 0 To gridListRoom.RowCount - 1
                            If gridListRoom.Rows(i).Cells("grdcbxChoose").Value = True Then
                                Dim roomId As Integer = gridListRoom.Rows(i).Cells("grdtxtRoomId").Value
                                bookromBus.InsertBookRoom(bookingIdModify, roomId)
                                roomBus.Update(roomId, "booked")
                            End If
                        Next
                    End If
                    MessageBox.Show("Update successfully!", "Update Reservation")
                Else
                    customerBus.InsertCustomer(txtFName.Text, txtLName.Text, txtPhone.Text, txtPassport.Text)
                    custId = customerBus.GetCustomerIdMax()
                    bookingBus.InsertBooking(custId, staffId, dateIn, dateOut)
                    Dim bookingId As Integer = bookingBus.GetBookingIdMax()
                    For i As Integer = 0 To gridListRoom.RowCount - 1
                        If gridListRoom.Rows(i).Cells("grdcbxChoose").Value = True Then
                            Dim roomId As Integer = gridListRoom.Rows(i).Cells("grdtxtRoomId").Value
                            bookromBus.InsertBookRoom(bookingId, roomId)
                            roomBus.Update(roomId, "booked")
                        End If
                    Next
                    MessageBox.Show("Book reservation successfully!", "New Reservation")
                End If
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Function IsBooking()
        Dim isBook As Boolean = True
        Try
            Dim strError As String = ""
            If txtFName.Text.Equals("") Then
                isBook = False
                strError = "Firt name"
            End If
            If txtLName.Text.Equals("") Then
                isBook = False
                strError = ", Last name"
            End If
            If txtPhone.Text.Equals("") Then
                isBook = False
                strError = ", Phone number"
            End If
            If txtPassport.Text.Equals("") Then
                isBook = False
                strError = ", Passport"
            End If
            If dtpDateIn.Text.Equals("") Then
                isBook = False
                strError = ", Date in"
            End If
            If dtpDateOut.Text.Equals("") Then
                isBook = False
                strError = ", Date out"
            End If
            If strError > "" Then
                strError = strError + " could not be blank"
            End If

            If Not txtPassport.Text.Equals("") AndAlso Not Util.IsOnlyNumber(txtPassport.Text) Then
                isBook = False
                strError = strError + ". Passport number only!"
            End If
            If Not txtPhone.Text.Equals("") AndAlso Not Util.IsOnlyNumber(txtPhone.Text) Then
                isBook = False
                strError = strError + ". Phone number wrong!"
            End If
            If Not dtpDateIn.Text.Equals("") AndAlso Not dtpDateOut.Text.Equals("") Then
                Dim dateIn As DateTime = dtpDateIn.Text
                Dim dateOut As DateTime = dtpDateOut.Text
                If dateIn > dateOut Then
                    strError = strError + ". Date Out >= Date In!"
                    isBook = False
                End If
            End If
            If Not IsChooseRoom() Then
                strError = strError + ". Must choose least 1!"
                isBook = False
            End If

            lblError.Text = strError
        Catch ex As Exception
            Throw
        End Try
        Return isBook
    End Function

    Private Function IsChooseRoom()
        IsChooseRoom = False
        For i As Integer = 0 To gridListRoom.RowCount - 1
            If gridListRoom.Rows(i).Cells("grdcbxChoose").Value = True Then
                IsChooseRoom = True
                Exit For
            End If
        Next
        Return IsChooseRoom
    End Function

    Private Sub SetClearReservation()
        txtFName.Enabled = True
        txtLName.Enabled = True
        txtPhone.Enabled = True
        txtPassport.Enabled = True
        dtpDateIn.Enabled = True
        gridListRoom.ReadOnly = False
        txtFName.Text = ""
        txtLName.Text = ""
        txtPhone.Text = ""
        txtPassport.Text = ""
        dtpDateIn.Text = Now.Date.ToShortDateString()
        dtpDateOut.Text = Now.Date.AddDays(1).ToShortDateString()
    End Sub

    Private Sub btnNewReservation_Click(sender As Object, e As EventArgs) Handles btnNewReservation.Click
        LoadDataTab_1()
    End Sub

#End Region

#Region "Tab 2"
    Private Sub LoadDataTab_2(ByVal searchPassport As String)
     
        Dim bookingBus As New BookingBUS()
        Dim listBooking As List(Of BookingDTO) = bookingBus.GetListBooking(Utilities.ConfigReader.GetString("idLogin"), searchPassport)
        If listBooking.Count > 0 Then
            Dim dt As New DataTable()
            dt.Columns.Add(New DataColumn("BookingId", GetType(String)))
            dt.Columns.Add(New DataColumn("CustomerName", GetType(String)))
            dt.Columns.Add(New DataColumn("Passport", GetType(String)))
            dt.Columns.Add(New DataColumn("DateIn", GetType(String)))
            dt.Columns.Add(New DataColumn("DateOut", GetType(String)))
            dt.Columns.Add(New DataColumn("Status", GetType(String)))
            dt.Columns.Add(New DataColumn("Rooms", GetType(String)))
            Dim dr As DataRow
            Dim bookingDto As BookingDTO
            For i As Integer = 0 To listBooking.Count - 1
                bookingDto = listBooking(i)
                dr = dt.NewRow()
                dr("BookingId") = bookingDto.BookingID
                dr("CustomerName") = bookingDto.CustomerName
                dr("Passport") = bookingDto.Passport
                dr("DateIn") = Format(bookingDto.DateIn, "dd/MM/yyyy")
                dr("DateOut") = Format(bookingDto.DateOut, "dd/MM/yyyy")
                dr("Status") = bookingDto.Status
                Dim bookroomBus As New BookRoomBUS()
                Dim listRoom As List(Of BookRoomDTO) = bookroomBus.GetListBookRoomByBookingId(bookingDto.BookingID)
                Dim strRooms As String = ""
                For j As Integer = 0 To listRoom.Count - 1
                    If strRooms > "" Then
                        strRooms = String.Format("{0}; {1} ", strRooms, listRoom(j).RoomID)
                    Else
                        strRooms = listRoom(j).RoomID
                    End If
                Next
                dr("Rooms") = strRooms
                dt.Rows.Add(dr)

            Next
            gridBookingCheckIn.DataSource = dt

        End If
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        LoadDataTab_2(txtSearchPassport.Text)
    End Sub

    Private Sub btnViewAll_Click(sender As Object, e As EventArgs) Handles btnViewAll.Click
        LoadDataTab_2("")
    End Sub

    Private Sub gridBookingCheckIn_SelectionChanged(sender As Object, e As EventArgs) Handles gridBookingCheckIn.SelectionChanged
        Try
            Dim index As Integer = gridBookingCheckIn.CurrentRow.Index
            grbControl.Hide()
            btnCheckIn.Enabled = True
            btnCancel.Enabled = True
            ' If (index > 0) Then
            'lblNameLogin.Text = gridBookingCheckIn.Rows(index).Cells("grdtxtCustomerName").Value.ToString()
            Dim bookingId As Integer = gridBookingCheckIn.Rows(index).Cells("grdtxtBookingId").Value.ToString()
            'grbControl.Visible = True
            Dim status As String = gridBookingCheckIn.Rows(index).Cells("grdtxtStatus").Value.ToString()
            If Not status.Equals("cancel") Then
                grbControl.Show()
                grbControl.Text = String.Format("Booking Id: {0}", bookingId)
                If status.Equals("checkin") Then
                    btnCheckIn.Enabled = False
                    btnCancel.Enabled = False
                End If
            End If

            ' End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        Try
            Dim bookingBus As New BookingBUS()
            Dim bookingId As Integer = Split(grbControl.Text, ("Booking Id:"))(1)
            Dim roomBus As New RoomBUS()
            Dim bookromBus As New BookRoomBUS()
            bookingBus.UpdateStatus(bookingId, "cancel")
            Dim listBookRoom As List(Of BookRoomDTO) = bookromBus.GetListBookRoomByBookingId(bookingId)
            For j As Integer = 0 To listBookRoom.Count - 1
                roomBus.Update(listBookRoom(j).RoomID, "free")
            Next
            '' 
            Dim index As Integer = gridBookingCheckIn.CurrentRow.Index
            ' If index > 0 Then
            gridBookingCheckIn.Rows(index).Cells("grdtxtStatus").Value = "cancel"
            grbControl.Hide()
            ' End If
            MessageBox.Show("Update Status Successfully!", "Update Status")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnCheckIn_Click(sender As Object, e As EventArgs) Handles btnCheckIn.Click
        Dim bookingBus As New BookingBUS()
        Dim bookingId As Integer = Split(grbControl.Text, ("Booking Id:"))(1)
        Dim receiptBus As New ReceiptBUS()
        receiptBus.InsertReceipt(bookingId, Format(Now, "hh:mm"))
        bookingBus.UpdateStatus(bookingId, "checkin")
        'LoadDataTab_2(txtSearchPassport.Text)
        Dim index As Integer = gridBookingCheckIn.CurrentRow.Index
        'If index > 0 Then
        gridBookingCheckIn.Rows(index).Cells("grdtxtStatus").Value = "checkin"
        btnCancel.Enabled = False
        btnCheckIn.Enabled = False
        'End If
        MessageBox.Show("Update Status Successfully!", "Update Status")
    End Sub

    Private Sub btnModify_Click(sender As Object, e As EventArgs) Handles btnModify.Click
        TabControlMain.SelectedIndex = 0
        Dim bookingId As Integer = Split(grbControl.Text, ("Booking Id:"))(1)
        lblHidden.Text = bookingId
        LoadDataTab_1(True)
        SetModify(bookingId)
    End Sub

    Private Sub SetModify(ByVal bookingId As Integer)
        Try
            Dim bookingBus As New BookingBUS()
            Dim bookroomBus As New BookRoomBUS()
            Dim customerBus As New CustomerBUS()
            Dim bookingModify As BookingDTO = bookingBus.GetByBookingId(bookingId)
            Dim listBookRoom As List(Of BookRoomDTO) = bookroomBus.GetListBookRoomByBookingId(bookingId)
            Dim customer As CustomerDTO = customerBus.GetCustomerByCustomerId(bookingModify.CustomerID)
            txtFName.Text = customer.FName
            txtLName.Text = customer.LName
            txtPhone.Text = customer.Phone
            txtPassport.Text = customer.Passport
            dtpDateIn.Text = bookingModify.DateIn
            dtpDateOut.Text = bookingModify.DateOut

            For i As Integer = 0 To gridListRoom.Rows.Count - 1
                Dim roomId As Integer = gridListRoom.Rows(i).Cells("grdtxtRoomId").Value
                For j As Integer = 0 To listBookRoom.Count - 1
                    If listBookRoom(j).RoomID = roomId Then
                        gridListRoom.Rows(i).Cells("grdcbxChoose").Value = True
                    End If
                Next
            Next
            If bookingModify.Status.Equals("checkin") Then
                txtFName.Enabled = False
                txtLName.Enabled = False
                txtPhone.Enabled = False
                txtPassport.Enabled = False
                dtpDateIn.Enabled = False
                gridListRoom.ReadOnly = True
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
#End Region

    Private Sub TabControlMain_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControlMain.SelectedIndexChanged
        Select Case TabControlMain.SelectedIndex
            Case 0 ''
                lblHidden.Text = ""
                LoadDataTab_1()
            Case 1
                txtSearchPassport.Text = ""
                LoadDataTab_2("")
            Case 2
                LoadTabService()
                'cbxRoomCheckIn.SelectedIndex = 0
            Case 3
                LoadTabCheckOut()             
        End Select
    End Sub

    Private Function GetBookingIdFromHidden() As Integer
        Dim bookingId As Integer = 0
        If lblHidden.Text > "" AndAlso IsNumeric(lblHidden.Text) Then
            bookingId = lblHidden.Text
        End If
        Return bookingId
    End Function

#Region "Tab 3 Service"

    Private Sub LoadTabService()
        Try
           
            Dim serviceBus As New ServiceBUS()
            Dim listSetvice As List(Of ServiceDTO) = serviceBus.GetListService()
            If listSetvice.Count > 0 Then
                Dim dt As New DataTable()
                dt.Columns.Add(New DataColumn("ServiceId", GetType(String)))
                dt.Columns.Add(New DataColumn("Name", GetType(String)))
                dt.Columns.Add(New DataColumn("Price", GetType(String)))
                dt.Columns.Add(New DataColumn("Quantity", GetType(Integer)))
                Dim dr As DataRow
                Dim serviceDto As ServiceDTO

                For i As Integer = 0 To listSetvice.Count - 1
                    serviceDto = listSetvice(i)
                    dr = dt.NewRow()
                    dr("ServiceId") = serviceDto.ServiceID
                    dr("Name") = serviceDto.Name
                    dr("Price") = serviceDto.Price
                    dr("Quantity") = 0
                    dt.Rows.Add(dr)
                Next
                gridServiceList.DataSource = dt
            End If
            Dim bookroomBus As New BookRoomBUS()
            cbxRoomCheckIn.DataSource = Nothing
            If bookroomBus.GetListBookRoomFromReceipt().Count > 0 Then
                cbxRoomCheckIn.DataSource = bookroomBus.GetListBookRoomFromReceipt()
                cbxRoomCheckIn.DisplayMember = "RoomId"
            End If

            ''
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub btnSubmitService_Click(sender As Object, e As EventArgs) Handles btnSubmitService.Click
        Try
            Dim bookroomBus As New BookRoomBUS()
            Dim ordersBus As New OrdersBUS()

            Dim staffId As Integer = Utilities.ConfigReader.GetString("idLogin")
            Dim roomId As Integer = cbxRoomCheckIn.Text
            Dim receiptId As Integer = bookroomBus.GetReceiptIDByRoomId(roomId)
            Dim listOrders As List(Of OrdersDTO) = ordersBus.GetListOrdersByReceiptID(receiptId, staffId, roomId)
            If receiptId > 0 AndAlso IsSubmitOrder(receiptId) Then
                For i As Integer = 0 To gridServiceList.Rows.Count - 1
                    If gridServiceList.Rows(i).Cells("grdtxtQuantityService").Value > 0 Then
                        Dim quantity As Integer = gridServiceList.Rows(i).Cells("grdtxtQuantityService").Value
                        Dim serviceId As Integer = gridServiceList.Rows(i).Cells("grdtxtServiceId").Value
                        If IsExistService(listOrders, serviceId) Then
                            ordersBus.Update(receiptId, staffId, serviceId, quantity, roomId)
                        Else
                            ordersBus.InsertOrders(receiptId, staffId, serviceId, quantity, roomId)
                        End If
                    End If
                Next
                MessageBox.Show("Order Successfully", "Submit Order")
            Else
                MessageBox.Show("Choose 1 service!", "Submit Order")
            End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Function IsExistService(ByVal listOrders As List(Of OrdersDTO), ByVal serverId As Integer) As Boolean
        IsExistService = False
        For i As Integer = 0 To listOrders.Count - 1
            If listOrders(i).ServiceID = serverId Then
                IsExistService = True
                Exit For
            End If
        Next
        Return IsExistService
    End Function
    Private Function IsSubmitOrder(ByVal recptId As Integer) As Boolean
        IsSubmitOrder = False
        For i As Integer = 0 To gridServiceList.Rows.Count - 1
            If gridServiceList.Rows(i).Cells("grdtxtQuantityService").Value > 0 Then
                IsSubmitOrder = True
                Exit For
            End If
        Next
        Return IsSubmitOrder
    End Function

    Private Sub cbxRoomCheckIn_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxRoomCheckIn.SelectedIndexChanged
        Try
            ''MessageBox.Show(cbxRoomCheckIn.SelectedIndex, "sss")
            '' If cbxRoomCheckIn.SelectedIndex > 0 Then
            Dim bookroomBus As New BookRoomBUS()
            Dim ordersBus As New OrdersBUS()
            Dim bookrooom As BookRoomDTO = cbxRoomCheckIn.SelectedItem
            Dim roomId As Integer = bookrooom.RoomID
            ''MessageBox.Show(roomId, "sss")
            Dim receiptId As Integer = bookroomBus.GetReceiptIDByRoomId(roomId)
            Dim staffId As Integer = Utilities.ConfigReader.GetString("idLogin")
            Dim listOrders As List(Of OrdersDTO) = ordersBus.GetListOrdersByReceiptID(receiptId, staffId, roomId)
            For i As Integer = 0 To gridServiceList.Rows.Count - 1
                gridServiceList.Rows(i).Cells("grdtxtQuantityService").Value = 0
                For j As Integer = 0 To listOrders.Count - 1
                    If gridServiceList.Rows(i).Cells("grdtxtServiceId").Value = listOrders(j).ServiceID Then
                        gridServiceList.Rows(i).Cells("grdtxtQuantityService").Value = listOrders(j).Quantity
                    End If
                Next
            Next
            ''End If
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub cbxRoomCheckIn_SelectedValueChanged(sender As Object, e As EventArgs) Handles cbxRoomCheckIn.SelectedValueChanged
        Try
           
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

#End Region

#Region "Tab Check Out"

    Private Sub LoadTabCheckOut()
        Dim staffId As Integer = Utilities.ConfigReader.GetString("idLogin")
        Dim bookingBus As New BookingBUS()
        Dim list As List(Of BookingDTO) = bookingBus.GetListCustomerByBooking(staffId)
        cbxCustomerName.DataSource = Nothing
        If list.Count > 0 Then
            cbxCustomerName.DataSource = list
            cbxCustomerName.DisplayMember = "CustomerName"
            cbxCustomerName.SelectedItem = 0
        End If

        cbxPaymentMethod.Items.Clear()
        cbxPaymentMethod.Items.Add("creditcard")
        cbxPaymentMethod.Items.Add("cash")
        cbxPaymentMethod.SelectedIndex = 0

    End Sub

#End Region

    Private toTalSub As Double = 0

    Private Sub cbxCustomerName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxCustomerName.SelectedIndexChanged
        toTalSub = 0
        LoadListRoomCheckOut()
        LoadListServicesCheckOut()
        Caculator()
    End Sub

    Private Sub LoadListRoomCheckOut()
        Dim bookingDto As BookingDTO = cbxCustomerName.SelectedItem
        Dim dura As Integer = Date.Compare(bookingDto.DateOut, bookingDto.DateIn)
        Dim totalRoom As Integer = 0
        Dim roomBus As New RoomBUS()
        Dim listRoom As List(Of RoomDTO) = roomBus.GetListRoomByBookingId(bookingDto.BookingID)
        Dim dt As New DataTable()
        dt.Columns.Add(New DataColumn("RoomId", GetType(String)))
        dt.Columns.Add(New DataColumn("Price", GetType(String)))
        dt.Columns.Add(New DataColumn("Duration", GetType(String)))
        dt.Columns.Add(New DataColumn("Total", GetType(String)))
        Dim dr As DataRow
        Dim roomDto As RoomDTO
        If listRoom.Count > 0 Then
            For i As Integer = 0 To listRoom.Count - 1
                roomDto = listRoom(i)
                dr = dt.NewRow()
                dr("RoomId") = roomDto.RoomID
                dr("price") = roomDto.Price
                dr("Duration") = String.Format("{0} days", dura)
                totalRoom = roomDto.Price * dura
                dr("Total") = String.Format("{0}$", totalRoom)
                toTalSub = toTalSub + totalRoom
                dt.Rows.Add(dr)
            Next
        End If
        gridRoomCheckOut.DataSource = dt

    End Sub

    Private Sub LoadListServicesCheckOut()
        Dim bookingDto As BookingDTO = cbxCustomerName.SelectedItem
        Dim totalService As Integer = 0
        Dim serviceBus As New ServiceBUS()
        Dim listService As List(Of ServiceDTO) = serviceBus.GetListServiceByBooking(bookingDto.BookingID)
        Dim dt As New DataTable()
        dt.Columns.Add(New DataColumn("Service", GetType(String)))
        dt.Columns.Add(New DataColumn("Price", GetType(String)))
        dt.Columns.Add(New DataColumn("Quantity", GetType(String)))
        dt.Columns.Add(New DataColumn("Total", GetType(String)))
        Dim dr As DataRow
        Dim serviceDto As ServiceDTO
        If listService.Count > 0 Then
            For i As Integer = 0 To listService.Count - 1
                serviceDto = listService(i)
                dr = dt.NewRow()
                dr("Service") = serviceDto.Name
                dr("Price") = serviceDto.Price
                dr("Quantity") = serviceDto.Quantity
                totalService = serviceDto.Price * serviceDto.Quantity
                dr("Total") = String.Format("{0}$", totalService)
                toTalSub = toTalSub + totalService
                dt.Rows.Add(dr)
            Next
        End If
        gridServiceCheckOut.DataSource = dt
    End Sub

    Private Function Caculator() As Double
        lblSubTotal.Text = String.Format("{0}$", toTalSub)
        Dim vat As Double = toTalSub * 10 / 100
        lblVat.Text = String.Format("{0}$ (10%)", vat)
        lblTotal.Text = String.Format("{0}$", toTalSub + vat)
        Return toTalSub + vat
    End Function

    Private Sub btnSubmitCheckOut_Click(sender As Object, e As EventArgs) Handles btnSubmitCheckOut.Click
        Try
            Dim receiptBus As New ReceiptBUS()
            Dim bookingDto As BookingDTO = cbxCustomerName.SelectedItem
            receiptBus.UpdateReceipt(bookingDto.BookingID, Format(Now, "hh:mm"), cbxPaymentMethod.Text, Caculator())

            Dim roomBus As New RoomBUS()
            Dim bookromBus As New BookRoomBUS()
            Dim bookingBUS As New BookingBUS()
            bookingBUS.UpdateStatus(bookingDto.BookingID, "cancel")
            Dim listBookRoom As List(Of BookRoomDTO) = bookromBus.GetListBookRoomByBookingId(bookingDto.BookingID)
            For j As Integer = 0 To listBookRoom.Count - 1
                RoomBUS.Update(listBookRoom(j).RoomID, "free")
            Next
            '' 
            MessageBox.Show("Check Out Successfully!", "Check Out")
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class